package com.xiaoq.matrix.repository.impl;



import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.xiaoq.matrix.entity.ContentMediaEntity;
import com.xiaoq.matrix.repository.IContentMediaRepository;

@Repository
public class ContentMediaRepositoryImpl implements IContentMediaRepository {
	
	@Autowired
	private Datastore datastore;

	@Override
	public ContentMediaEntity getContentMedia(String name) {
		
		
		ContentMediaEntity contentMedia= datastore.createQuery(ContentMediaEntity.class).field("name").equal(name).get();
		return contentMedia;
	}

	@Override
	public ContentMediaEntity getContentMediaById(String id) {
		ContentMediaEntity contentMedia=null;
		if(StringUtils.isNotEmpty(id)){
		contentMedia = datastore.get(ContentMediaEntity.class,id);
		}
		return contentMedia;
	}

	@Override
	public List<ContentMediaEntity> getContentMedias() {
		Query<ContentMediaEntity>contentMediaQuery = datastore.find(ContentMediaEntity.class);
		return contentMediaQuery.asList();
	}
	
	

}
